﻿using ElectronicSelling.BaseEntity;
using ElectronicSelling.BusinessLogic;
using ElectronicSelling.Utilities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicSelling
{
    public partial class DetailProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetDetailProduct();                
            }
        }

        protected void GetDetailProduct()
        {
            if (Request.QueryString["pid"] != null)
            {
                try
                {
                    Product product = new Product();
                    product.ProductId = Convert.ToInt32(Request.QueryString["pid"].ToString());
                    HomeProductLogic.UpdateVisited(product);
                    DataTable dt = HomeProductLogic.GetProductDetailById(product);
                    rptDetailView.DataSource = dt;
                    rptDetailView.DataBind();
                }
                catch (Exception)
                {
                    Response.Redirect(Directory.Error);
                }
            }
        }

        protected string GetPathSection()
        {
            if (Request.QueryString["sid"] != null)
            {
                try
                {
                    Section section = new Section();
                    section.SectionId = Convert.ToInt32(Request.QueryString["sid"].ToString());
                    return HomeProductLogic.GetSectionById(section);
                }
                catch (Exception)
                {
                    return null;
                }
            }
            return null;
        }

        protected string GetPathCategory()
        {
            if (Request.QueryString["cid"] != null)
            {
                try
                {
                    Category category = new Category();
                    category.CategoryId = Convert.ToInt32(Request.QueryString["cid"].ToString());
                    return HomeProductLogic.GetCategoryById(category);
                }
                catch (Exception)
                {
                    return null;
                }
            }
            return null;
        }

        protected string GetPathProduct()
        {
            if (Request.QueryString["pid"] != null)
            {
                try
                {
                    Product product = new Product();
                    product.ProductId = Convert.ToInt32(Request.QueryString["pid"].ToString());
                    return HomeProductLogic.GetProductById(product);
                }
                catch (Exception)
                {
                    return null;
                }
            }
            return null;
        }

        protected void lbtBuyAccept_Click(Object sender, EventArgs e)
        {
            //Session.RemoveAll();
            int productId = Convert.ToInt32(Request.QueryString["pid"].ToString());
            //CreateCart();
            Response.Redirect("Cart.aspx?cartAction=add&pid=" + productId + "");


        }

        
    }
}